package com.akbar.mapper;

import com.akbar.entity.SysUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author akbar
 * @since 2025-07-21
 */
public interface SysUserMapper extends BaseMapper<SysUser> {

    // 根据id获取用户角色
    @Select("""
                SELECT r.role_name
                FROM sys_user_role ur
                JOIN sys_role r ON ur.role_id = r.id
                WHERE ur.user_id = #{userId};
            """)
    List<String> selectRoleByUserId(Integer userId);

    // 根据用户id获取权限列表
    @Select("""
                SELECT DISTINCT p.permission_key
                FROM sys_user_role ur
                JOIN sys_role_permission rp ON ur.role_id = rp.role_id
                JOIN sys_permission p ON rp.permission_id = p.id
                WHERE ur.user_id = #{userId}
            """)
    List<String> getPermissionsByUserId(Integer userId);
}
